local items = {
  settingsfile = "335狂暴战.json",
  { type = "separator" },
  { type = "title", text = "335狂暴战 |c0000CED1 糊涂虫" },

  { type = "separator" },
  { type = "title", text = "|cffFFFF00保命功能" },
  { type = "separator" },  
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(55694))..":26:26\124t  狂暴回复 < HP%", tooltip = "施放狂暴回复 < HP%", enabled = true, value = 20, key = "EnragedRegeneration" },
  { type = "entry", text = "\124T"..GetItemIcon(36894)..":26:26\124t 治疗石 < HP%", tooltip = "使用 治疗石 < HP%", enabled = true, value = 30, key = "FelHealthstone" },

	{ type = "separator" },
  { type = "title", text = "|cffFFFF00输出辅助" },
  { type = "separator" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(54999))..":26:26\124t 工程手套 < 码", tooltip = "工程手套CD好了就用", enabled = true, value = 41, key = "UseHand" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(55016))..":26:26\124t 工程鞋子（右Ctrl）", tooltip = "按住右Ctrl施放工程疾跑", enabled = true, key = "UseFoot" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(25264))..":26:26\124t 自动爆发（英勇、嗜血、狂乱）", tooltip = "嗜血、英勇、狂乱等进行自动开启爆发", enabled = true, key = "AutoBurst" },

  { type = "separator" },
  { type = "title", text = "|cffFFFF00其他辅助" },
  { type = "separator" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(18499))..":26:26\124t  狂暴之怒解恐 ", tooltip = "在恐惧状态后释放解除恐惧 ", enabled = true , key = "BerserkerRage" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(11578))..":26:26\124t  冲锋拦截", tooltip = "冲锋拦截", enabled = true, key = "Charge" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(2687))..":26:26\124t  血性狂暴 怒气 < %", tooltip = "血性狂暴，CD好了并且怒气 < ", enabled = true, value = 20, key = "Bloodrage" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(6603))..":26:26\124t  自动目标", tooltip = "自动目标", enabled = true, key = "AutoAttack" },
  { type = "entry", text = "\124T"..GetItemIcon(25289)..":26:26\124t  1为战斗怒吼2为命令怒吼", tooltip = "1为战斗怒吼2为命令怒吼", enabled = true, value = 2, key = "Shout" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(54999))..":26:26\124t 调试模式", tooltip = "开启后打印施法信息", enabled = false, key = "Debug" },
	
	{ type = "separator" },
  { type = "title", text = "|cffFFFF00狂暴战" },
  { type = "separator" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(7386))..":26:26\124t  破甲攻击", tooltip = "是否释放破甲攻击", enabled = false, key = "SunderArmor" },
  { type = "entry", text = "\124T"..select(3, GetSpellInfo(25234))..":26:26\124t  斩杀 怒气 > %", tooltip = "是否释放斩杀，及斩杀怒气阈值", enabled = true, value = 50, key = "Execute" },
	{ type = "entry", text = "\124T"..select(3, GetSpellInfo(2458))..":26:26\124t  狂暴战输出，英勇打击怒气 > %", tooltip = "狂暴战输出循环，英勇打击怒气 >", enabled = true, value = 25, key = "Dps" },
};
 
local function GetSetting(name)
    for k, v in ipairs(items) do
        if v.type == "entry"
         and v.key ~= nil
         and v.key == name then
            return v.value, v.enabled
        end
    end
end;

local function OnLoad()
  ni.GUI.AddFrame("335狂暴战", items);
end;

local function OnUnLoad()  
  ni.GUI.DestroyFrame("335狂暴战");
end;

local spells = {
  --General
  WarStomp = {id = 20549, name = GetSpellInfo(20549), tooltip = "战争践踏"},  --战争践踏
  AutoAttack = {id = 6603, name = GetSpellInfo(6603), tooltip = "攻击"},  --攻击
  Throw = {id = 2764, name = GetSpellInfo(2764), tooltip = "投掷"},  --投掷
  FelHealthstone = {id = 36894, name = GetItemInfo(36894), tooltip = "治疗石"},  --治疗石
  --Arms
  ThunderClap = {id = 25264, name = GetSpellInfo(25264), tooltip = "雷霆一击"},  --雷霆一击
  Charge = {id = 11578, name = GetSpellInfo(11578), tooltip = "冲锋"},  --冲锋
  Hamstring = {id = 1715, name = GetSpellInfo(1715), tooltip = "断筋"},  --断筋
  Rend = {id = 11574, name = GetSpellInfo(11574), tooltip = "撕裂"},  --撕裂
  BattleStance = {id = 2457, name = GetSpellInfo(2457), tooltip = "战斗姿态"},  --战斗姿态
  Retaliation = {id = 20230, name = GetSpellInfo(20230), tooltip = "反击风暴"}, --反击风暴
  MockingBlow = {id = 694, name = GetSpellInfo(694), tooltip = "惩戒痛击"},  --惩戒痛击
  Overpower = {id = 7384, name = GetSpellInfo(7384), tooltip = "压制"},  --压制
  HeroicStrike = {id = 47450, name = GetSpellInfo(47450), tooltip = "英勇打击"},  --英勇打击
  HeroicThrow = {id = 57755, name = GetSpellInfo(57755), tooltip = "英勇投掷"},  --英勇投掷
  --Fury
  BerserkerStance = {id = 2458, name = GetSpellInfo(2458), tooltip = "狂暴姿态"},  --狂暴姿态
  Recklessness = {id = 1719, name = GetSpellInfo(1719), tooltip = "鲁莽"}, --鲁莽
  DeathWish = {id = 12292, name = GetSpellInfo(12292), tooltip = "死亡之愿"}, --鲁莽
  BloodThirsty = {id = 23881, name = GetSpellInfo(23881), tooltip = "嗜血"}, --嗜血
  Cleave = {id = 47520, name = GetSpellInfo(47520), tooltip = "顺劈斩"}, --顺劈斩
  Execute = {id = 47471, name = GetSpellInfo(47471), tooltip = "斩杀"}, --斩杀
  Whirlwind = {id = 1680, name = GetSpellInfo(1680), tooltip = "旋风斩"},--旋风斩
  DemoralizingShout = {id = 25202, name = GetSpellInfo(25202), tooltip = "挫志怒吼"}, --挫志怒吼
  VictoryRush = {id = 34428, name = GetSpellInfo(34428), tooltip = "乘胜追击"}, --乘胜追击
  Slam = {id = 47475, name = GetSpellInfo(47475), tooltip = "猛击"}, --猛击
  
  SlamBuff = {id = 46916, name = GetSpellInfo(46916), tooltip = "猛击！"}, --猛击
  IntimidatingShout = {id = 5246, name = GetSpellInfo(5246), tooltip = "破胆怒吼"}, --破胆怒吼
  Pummel = {id = 6552, name = GetSpellInfo(6552), tooltip = "拳击"}, --拳击
  BerserkerRage = {id = 18499, name = GetSpellInfo(18499), tooltip = "狂暴之怒"}, --狂暴之怒
  EnragedRegeneration = {id = 55694, name = GetSpellInfo(55694), tooltip = "狂暴回复"}, --狂暴回复
  ChallengingShout = {id = 1161, name = GetSpellInfo(1161), tooltip = "挑战怒吼"},  --挑战怒吼
  Intercept = {id = 20252, name = GetSpellInfo(20252), tooltip = "拦截"},  --拦截
  BattleShout = {id = 47436, name = GetSpellInfo(47436), tooltip = "战斗怒吼"},  --战斗怒吼
  CommandingShout = {id = 47440, name = GetSpellInfo(47440), tooltip = "命令怒吼"},  --命令怒吼
  --Protection
  ConcussionBlow = {id = 12809, name = GetSpellInfo(12809), tooltip = "震荡猛击"},  --震荡猛击
  Vigilance = {id = 50720, name = GetSpellInfo(50720), tooltip = "警戒"},  --警戒
  Taunt = {id = 355, name = GetSpellInfo(355), tooltip = "嘲讽"},  --嘲讽
  SunderArmor = {id = 7386, name = GetSpellInfo(7386), tooltip = "破甲攻击"}, --破甲攻击
  Disarm = {id = 676, name = GetSpellInfo(676), tooltip = "缴械"},  --缴械
  SpellReflection = {id = 23920, name = GetSpellInfo(23920), tooltip = "法术反射"},  --法术反射
  Shockwave = {id = 46968, name = GetSpellInfo(46968), tooltip = "震荡波"},  --震荡波
  ShieldWall = {id = 871, name = GetSpellInfo(871), tooltip = "盾墙"},  --盾墙
  ShieldSlam = {id = 47488, name = GetSpellInfo(47488), tooltip = "盾牌猛击"},  --盾牌猛击
  ShieldBlock = {id = 2565, name = GetSpellInfo(2565), tooltip = "盾牌格挡"},  --盾牌格挡
  Revenge = {id = 57823, name = GetSpellInfo(57823), tooltip = "复仇"},  --复仇
  DefensiveStance = {id = 71, name = GetSpellInfo(71), tooltip = "防御姿态"},  --防御姿态
  ShieldBash = {id = 72, name = GetSpellInfo(72), tooltip = "盾击"},  --盾击
  Devastate = {id = 47498, name = GetSpellInfo(47498), tooltip = "毁灭打击"}, --毁灭打击
  LastStand = {id = 12975, name = GetSpellInfo(12975), tooltip = "破釜沉舟"},  --破釜沉舟
  Bloodrage = {id = 2687, name = GetSpellInfo(2687), tooltip = "血性狂暴"}  --血性狂暴
};

local Cache = {
    enemiesn = ni.player.enemiesinrange(30),
}

local queue = {
  "Debug",
  "Pause", -- 坐骑或者未进战斗
  "AutoAttack", -- 开始攻击
  "EnragedRegeneration", -- 狂暴回复
  "FelHealthstone", -- 吃糖
  "BerserkerRage", -- 狂暴之怒
  "Charge",  -- 冲锋
  "Bloodrage", -- 血性狂怒
	"UseHand", -- 工程手
	"UseFoot", -- 工程鞋
	"AutoBurst", -- 自动爆发
	"Dps", -- 狂暴输出
  "Shout" -- 怒吼
};

local abilities = {
  ["Debug"] = function()
		local _, enebled = GetSetting("Debug")
        if enebled then
            ni.vars.debug = true
        else
            ni.vars.debug = false
        end
	end,

  ["Pause"] = function()  --停止条件
    if ni.tnr.pause() then
      return true
    end
  end,
  
  
  ["AutoAttack"] = function()  --自动攻击
  local _, enabled = GetSetting("AutoAttack")
    if enabled and ni.unit.incombat("player") and (not IsCurrentSpell(spells.AutoAttack.id) or not UnitCanAttack("player", "target")) then
      ni.spell.cast(spells.AutoAttack.name)
    end
  end,

  ["EnragedRegeneration"] = function()  --狂暴回复
    local value, enabled = GetSetting("EnragedRegeneration")
    if enabled and ni.unit.incombat("player") and ni.spell.cd(spells.EnragedRegeneration.id) < 1 and ni.player.hp() <= value then
        ni.spell.cast(spells.EnragedRegeneration.name)
        return true;
    end 
  end,

  ["FelHealthstone"] = function()  -- 治疗石
    local value, enabled = GetSetting("FelHealthstone")
		if enabled and ni.unit.incombat("player") and ni.player.hasitem(spells.FelHealthstone.id) and ni.spell.cd(spells.FelHealthstone.id) < 1 and ni.unit.hp("player") <= value then
			ni.spell.cast(spells.FelHealthstone.name)
			return true;
		end 
	end,

  ["BerserkerRage"] = function()  --狂暴之怒
    local value, enabled = GetSetting("BerserkerRage")
    if enabled and ni.unit.isfleeing("player") and ni.spell.cd(spells.BerserkerRage.id) < 1 then
			ni.spell.cast(spells.BerserkerRage.name)
			return true;
    end 
  end,

  ["Charge"] = function()
    local _, enabled = GetSetting("Charge")  --冲锋
    if enabled 
      and IsSpellInRange(spells.Charge.name,"target")==1 
      and ni.unit.incombat("target") then
      if ni.tnr.valid("target", spells.Intercept.id) and ni.spell.cast(spells.Intercept.name, "target") then 
        return true 
      end
      if ni.tnr.valid("target", spells.Charge.id) and ni.spell.cast(spells.Charge.name, "target") then 
        return true
      end
    end
  end,

  ["Bloodrage"] = function()
    local value, enabled = GetSetting("Bloodrage")  --血性狂暴
    if enabled and ni.unit.incombat("player") and ni.unit.power("player") < value and ni.spell.available(spells.Bloodrage.id)  then
      ni.spell.cast(spells.Bloodrage.name)
      return true
    end
  end,
  

	["UseHand"] = function()
		local value, enabled = GetSetting("UseHand")
			if enabled then
				ni.tnr.useinventoryitem(10, value)
			end
		end,

	["UseFoot"] = function()
    if ni.tnr.isrightctrl() then
      ni.tnr.useinventoryitem(8)
    end
  end,

	["AutoBurst"] = function()
      local _, enabled = GetSetting("AutoBurst")
        if (enabled and ni.unit.buffs("player", "嗜血||英勇||狂乱")) or ni.tnr.isleftctrl() then
            
            -- 饰品
            ni.tnr.useinventoryitem(13) 
            ni.tnr.useinventoryitem(14)

            -- 巨魔狂暴
            if ni.tnr.race() == "巨魔" then
              if ni.spell.available("狂暴") then
                  ni.spell.cast("狂暴")
                  return true
              end
          end

          -- 兽人血性狂怒
          if ni.tnr.race() == "兽人" then
              if ni.spell.available("血性狂怒") then
                  ni.spell.cast("血性狂怒")
                  return true
              end
          end
            
            -- 死亡之愿
            if ni.spell.available(spells.DeathWish.id) then
                ni.spell.cast(spells.DeathWish.name)
                return true
            end

            -- 鲁莽
            if ni.spell.available(spells.Recklessness.id) then
              ni.spell.cast(spells.Recklessness.name)
              return true
            end
        end
  end,

	["Dps"] = function() 
            local heroicStrikeValue, enabled = GetSetting("Dps")
            local executeValue, executeEnabled = GetSetting("Execute")
	    local _, sunderArmorEnabled = GetSetting("SunderArmor")

		if enabled  and ni.tnr.attack() then
      -- 狂暴姿态
			if not ni.tnr.shapes(3) then 
				ni.spell.cast(spells.BerserkerStance.name)
			end

			local power = ni.player.power()

      -- 补破甲攻击dot
			if sunderArmorEnabled and ni.unit.debuffremaining("target", spells.SunderArmor.id) < 4 and ni.spell.available(spells.SunderArmor.id) then -- 破甲攻击小于3秒优先补破甲
				ni.spell.cast(spells.SunderArmor.name, "target")
				return true
			end

      -- AOE优先，毛伤害才是王道
			if #ni.unit.enemiesinrange("player", 8) > 1 then
        if ni.spell.available(spells.Cleave.id) then -- 顺劈 
					ni.spell.cast(spells.Cleave.name)
				end
				if ni.spell.available(spells.Whirlwind.id) then -- 旋风斩
					ni.spell.cast(spells.Whirlwind.name)
          return true
				end
      else
        -- 英勇打击
        if power > heroicStrikeValue or (ni.spell.cd(spells.BloodThirsty.id) > 2 and ni.spell.cd(spells.Whirlwind.id) > 2) then
          ni.spell.cast(spells.HeroicStrike.name)
        end
			end

      -- 斩杀
			if executeEnabled and ni.unit.hp("target") < 20 and power > executeValue and ni.spell.available(spells.Execute.id) then 
				ni.spell.cast(spells.Execute.name)
				return true
			end

      -- 触发猛击的时候
			if ni.unit.buffstacks("player", spells.SlamBuff.id) > 1 and ni.spell.available(spells.Slam.id) then 
				ni.spell.cast(spells.Slam.name)
        return true
			end

      -- 嗜血
			if ni.spell.available(spells.BloodThirsty.id) then 
				ni.spell.cast(spells.BloodThirsty.name)
        return true
			end

      -- 旋风斩
      if ni.spell.available(spells.Whirlwind.id) then 
				ni.spell.cast(spells.Whirlwind.name)
        return true
			end

      -- 猛击
      if ni.unit.buffstacks("player", spells.SlamBuff.id) > 0 and ni.spell.available(spells.Slam.id) then 
				ni.spell.cast(spells.Slam.name)
        return true
			end

      -- 乘胜追击
      -- if ni.spell.available(spells.VictoryRush.id) then 
			-- 	ni.spell.cast(spells.VictoryRush.name)
      --   return true
			-- end

      -- 破甲
      if sunderArmorEnabled and ni.spell.available(spells.SunderArmor.id) then
				ni.spell.cast(spells.SunderArmor.name)
				return true
			end
		end
	end,

  ["Shout"] = function()  --1为战斗怒吼 其他为命令怒吼
  local value, enabled = GetSetting("Shout")
    if enabled then
      if value == 1 then
        if not ni.player.buff(spells.BattleShout.id) and ni.spell.available(spells.BattleShout.id) then
          ni.spell.cast(spells.BattleShout.name)
         return true 
        end
      elseif not ni.player.buff(spells.CommandingShout.id) and ni.spell.available(spells.CommandingShout.id) then
        ni.spell.cast(spells.CommandingShout.name) 
        return true  
      end
    end
  end,

};
ni.bootstrap.profile("335狂暴战", queue, abilities, OnLoad, OnUnLoad);  
